<?php

class ReturnpoliciesController extends AppController {

    var $name = 'Returnpolicies';
    var $uses = array('Returnpolicy');
    var $helpers = array('Html', 'Form', 'Javascript', 'Fck');

    function beforeFilter() {
        parent::beforeFilter();
        $this->Auth->allowedActions = array('*');
    }

    function backstage_index() {
        $this->Returnpolicy->recursive = 0;
        $this->set('returnpolicies', $this->paginate());
    }

    function backstage_view($id = null) {
        if (!$id) {
            $this->Session->setFlash(__('Invalid returnpolicy', true));
            $this->redirect(array('action' => 'index'));
        }
        $this->set('returnpolicy', $this->Returnpolicy->read(null, $id));
    }

    function backstage_add() {
        $this->layout = 'admin';
        $id = $this->Auth->user('id');
        if (!empty($this->data)) {
            $this->data['Returnpolicy']['seller_id'] = $id;
            $isexist = $this->Returnpolicy->find('count', array('conditions' => array('Returnpolicy.seller_id' => $id)));
            if ($isexist > 0) {
                $uinfo = $this->Returnpolicy->findBySellerId($id);
                $this->data['Returnpolicy']['id'] = $uinfo['Returnpolicy']['id'];
            }
            $this->Returnpolicy->create();
            if ($this->Returnpolicy->save($this->data)) {
                $this->Session->setFlash(__('The Return policy has been saved.', true));
            } else {
                $this->Session->setFlash(__('The Return policy could not be saved. Please, try again.', true));
            }
        }

        $this->set('returnpolicy', $this->Returnpolicy->findBySellerId($id));
    }

    function backstage_edit($id = null) {
        if (!$id && empty($this->data)) {
            $this->Session->setFlash(__('Invalid returnpolicy', true));
            $this->redirect(array('action' => 'index'));
        }
        if (!empty($this->data)) {
            if ($this->Returnpolicy->save($this->data)) {
                $this->Session->setFlash(__('The Return policy has been saved', true));
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(__('The returnpolicy could not be saved. Please, try again.', true));
            }
        }
        if (empty($this->data)) {
            $this->data = $this->Returnpolicy->read(null, $id);
        }
    }

    function backstage_delete($id = null) {
        if (!$id) {
            $this->Session->setFlash(__('Invalid id for returnpolicy', true));
            $this->redirect(array('action' => 'index'));
        }
        if ($this->Returnpolicy->delete($id)) {
            $this->Session->setFlash(__('Returnpolicy deleted', true));
            $this->redirect(array('action' => 'index'));
        }
        $this->Session->setFlash(__('Returnpolicy was not deleted', true));
        $this->redirect(array('action' => 'index'));
    }

    function index() {
        $this->layout = 'innerhome';
        $id = $this->Auth->user('id');
        if (!empty($this->data)) {
            $this->data['Returnpolicy']['seller_id'] = $id;
            $isexist = $this->Returnpolicy->find('count', array('conditions' => array('Returnpolicy.seller_id' => $id)));
            if ($isexist > 0) {
                $uinfo = $this->Returnpolicy->findBySellerId($id);

                $this->data['Returnpolicy']['id'] = $uinfo['Returnpolicy']['id'];
            }
            $this->Returnpolicy->create();
            if ($this->Returnpolicy->save($this->data)) {
                $this->Session->setFlash(__('The Return policy has been saved.', true));
            } else {
                $this->Session->setFlash(__('The Return policy could not be saved. Please, try again.', true));
            }
        }

        $this->set('returnpolicy', $this->Returnpolicy->findBySellerId($id));
    }

}

?>